package com.it.myh;

import java.io.*;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: Ev_0214_02    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2023/2/14 23:29   // 时间
 * @Version: 1.0     // 版本
 */
public class Ev_0214_02 {

    public static void main(String[] args) {

        //1.创建File类的对象，指明读入和写出的文件
        File file = new File("D:\\restart.txt");
        File cv = new File("D:\\cv.txt");
        FileReader fileReader = null;
        FileWriter fileWriter = null;

        try {
            //2.创建输入流和输出流对象
            fileReader = new FileReader(file);
            fileWriter = new FileWriter(cv);

            //3.先读后写
            int read = fileReader.read();
            while (read != -1){
                char c = (char) read;
                //读一个，写一个
                fileWriter.write(c);
                read = fileReader.read();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                //4.关流
                if (fileReader != null && fileWriter != null){
                    fileReader.close();
                    fileWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
